var app = getApp(),
  common = require("../../common/common.js");


Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  // 获取用户信息
  onGotUserInfo(e) {
    console.log(e.detail.errMsg)
    console.log(e.detail.userInfo)
    console.log(e.detail.rawData)    
  },
  // 前往首页
  toIndex(){
    wx.navigateTo({
      url:'/xc_train/pages/index/index',
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  // 去注册
  toSetin(e){
    // type 0 未注册 1为已注册
    wx.navigateTo({
      url: '/xc_train/pages/theLogin/registered/registered?type=0'
    })
  },
  // 忘记密码
  forgetPw(e) {
    wx.navigateTo({
      url: '/xc_train/pages/theLogin/registered/registered?type=1'
    })
  },
  // 登录
  login(e){
    console.log(e)
    let tel = e.detail.value.tel
    let pwd = e.detail.value.pwd    
    app.util.request({
      url: 'entry/wxapp/changePassword',
      data: {
        pwd: pwd,
        tel: tel,
      },
      success: function (a) {
        console.log(a)        
        wx.showToast({
          title: a.data.message,
          icon: 'none',
          duration: 2000,
        })
        if(a.data.code==0){
          wx.redirectTo({
            url: '/xc_train/pages/index/index',
            success: function(res) {},
            fail: function(res) {},
            complete: function(res) {},
          })
        }
      }
    })
  },
  onLoad: function (a) {
    var n = this;
    common.login(n)
    var t = app.userinfo;
    console.log(t)
  },
  onReady: function () {
    
  },
  onShow: function () {
    console.log(wx.getStorageSync("users"))
  },
  onHide: function () {

  },
  onUnload: function () {

  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  },
  onShareAppMessage: function () {

  }
})